package com.game;

import java.util.Vector;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.view.MotionEvent;

public class Scene4 extends Scene {

	private Bitmap m_Background;
	private Vector<ButtonPlanet> m_Screens;
	
	public Scene4(SceneManager parent, int ref)
	{
		super(parent);
		m_Screens = new Vector<ButtonPlanet>();
		m_Background = null;
		
		Start(ref);		
	}
	
	@Override
	public void Draw(Canvas canvas) 
	{
		canvas.drawBitmap(m_Background, 0, 0, null);
		for (ButtonPlanet button : m_Screens) 
		{
			button.Draw(canvas);
		}

	}

	@Override
	public void End() {
		// TODO Auto-generated method stub

	}

	@Override
	public void Start() {
		// TODO Auto-generated method stub

	}
	
	public void Start(int ref)
	{
		m_Background = LoadBitmap( GameData.getGameData().PlanetBGName(ref) );
		// Load buttons
		
		ButtonPlanet auxB;
		
		auxB = new ButtonPlanet(0, 60, 80, false, LoadBitmap(R.drawable.scene4_sub1),LoadBitmap( R.drawable.scene4_sub1_off), LoadBitmap(R.drawable.scene4_locked));
		m_Screens.add(auxB);
		
		auxB = new ButtonPlanet(1, 160, 40, true, LoadBitmap(R.drawable.scene4_sub1),LoadBitmap( R.drawable.scene4_sub1_off), LoadBitmap(R.drawable.scene4_locked));
		m_Screens.add(auxB);
		
		auxB = new ButtonPlanet(1, 250, 10, true, LoadBitmap(R.drawable.scene4_sub1),LoadBitmap( R.drawable.scene4_sub1_off), LoadBitmap(R.drawable.scene4_locked));
		m_Screens.add(auxB);
		
		auxB = new ButtonPlanet(1, 340, 40, true, LoadBitmap(R.drawable.scene4_sub1),LoadBitmap( R.drawable.scene4_sub1_off), LoadBitmap(R.drawable.scene4_locked));
		m_Screens.add(auxB);
		
		auxB = new ButtonPlanet(1, 400, 80, true, LoadBitmap(R.drawable.scene4_sub1),LoadBitmap( R.drawable.scene4_sub1_off), LoadBitmap(R.drawable.scene4_locked));
		m_Screens.add(auxB);
	}

	@Override
	public void Update() {
		//Hack
		if(m_Screens.elementAt(0).Used())
		{
			mParentSM.ChangeScene(new Scene5(mParentSM));
		}

	}

	@Override
	public boolean handleTouch(MotionEvent event)
	{
		synchronized (mSurfaceHolder) 
		{
			int tx,ty;
			tx = (int)event.getX();
			ty = (int)event.getY();
			
			
			for (ButtonPlanet button : m_Screens) 
			{
				button.TryTouch(tx, ty);				
			}			
			
		}
		return true;
	}

}
